package com.boss.controller;

import com.alibaba.fastjson.JSON;
import com.boss.entity.BossAdmin;
import com.boss.entity.BossInformation;
import com.boss.entity.JobOffers;
import com.boss.service.JobOffersService;
import com.boss.util.Contans;
import com.boss.util.TypeConversion;
import javafx.application.Application;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

@Controller
    @RequestMapping("/jobOffers")
public class JobOffersController {
    @Autowired
    private JobOffersService jobOffersService;
    Boolean falg = null;//添加验证
    //添加一个职位.
    @RequestMapping("/addJobOffers")
    public String addJobOffers(JobOffers jobOffers, HttpServletRequest request,
                               HttpSession session,
                                @RequestParam(value="positionCategory",required = false)String positionCategory,
                               @RequestParam(value = "position",required = false)String positionId,
                               @RequestParam(value = "locationCode",required = false)String locationCodeId,
                                @RequestParam(value = "address",required = false)String address,
                               @RequestParam(value = "experience",required = false)String experience,
                               @RequestParam(value = "degree",required = false)String degree,
                               @RequestParam(value = "lowSalary",required = false)String lowSalary,
                               @RequestParam(value = "highSalary",required = false)String highSalary,
                               @RequestParam(value = "description",required = false)String description,
                               @RequestParam(value = "esist",required = false)String esist){
//        System.out.println(positionCategory+"=="+positionId+"=="+locationCodeId+"=="+address+"=="+experience+"=="+degree+"=="+
//                lowSalary+"=="+highSalary+"=="+description+"=="+esist+"==");

//        int id = ((BossInformation)session.getAttribute(Contans.LOGINSESSION)).getBossCardId();//获取boss编号

        jobOffers.setJobLabelName(positionCategory);//职位名称
        jobOffers.setJobClassifyId(TypeConversion.Objects(positionId));//职位类型
        jobOffers.setCityClassifyId(TypeConversion.Objects(locationCodeId));//工作城市
        jobOffers.setAddress(address);//工作地点.
        jobOffers.setWorkExperienceId(TypeConversion.Objects(experience));//工作经验
        jobOffers.setEducationId(TypeConversion.Objects(degree));
        jobOffers.setStartSalaryRange(TypeConversion.Objects(lowSalary));//最低薪资
        jobOffers.setEndSalaryRange(TypeConversion.Objects(highSalary));//最高薪资.
        jobOffers.setJobDescription(description);//职位描述
        jobOffers.setJobLabelName(esist);//职位描述
        jobOffers.setJobName("123");//boss名称
        jobOffers.setPayroll(12);//每年发薪

        jobOffers.setBossCardId(1);//添加boos编号
        jobOffers.setCreateDate(new Date());//添加创建时间
        jobOffers.setCompanyInformationId(1);//公司信息编号
        String ss = JSON.toJSONString(jobOffers);
        System.out.println(ss);
        if(jobOffersService.addJobOffers(jobOffers) == 1){//判断是否添加成功
            falg = true;
                return "/z_addJboOffersOk";
        }else{
            falg = false;
                return "/z_addjobfferNo";
        }
    }
    //验证添加是否成功
    @RequestMapping("/addYesOrNo")
    public Boolean addYesOrNo(){
        System.out.println(falg);
        return falg;
    }
//    //显示职位审核列表
//    @RequestMapping("/getJobOffers")
//    public String list(){
//        List<JobOffers> list =  jobOffersService.getJobOffers();
//        String json =  JSON.toJSONString(list);
//
//        return  json;
//    }
}
